// Obsolete!
// This file is removed.

package com.devdan.headsetfix;

import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class MyPhoneStateListener extends PhoneStateListener{

	HeadsetfixActivity myHeadsetfixActivity;
	// Always gets a STATE_IDLE when starting, so ignore first occurance
	boolean firstState;
	
    public MyPhoneStateListener(HeadsetfixActivity headsetfixActivity) {
    	myHeadsetfixActivity = headsetfixActivity;
    	firstState = true;
	}

	@Override
	// This function will bring back the activity after hanging up the hook.
    public void onCallStateChanged(int state, String incomingNumber) {
		if (!firstState) {
	        if(TelephonyManager.CALL_STATE_IDLE == state) {
	        	Intent intent = new Intent(myHeadsetfixActivity,HeadsetfixActivity.class);
	        	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	        	myHeadsetfixActivity.startActivity(intent);	        	
	        }
		}
	    firstState = false;
    }
}
